package com.chuangke.system.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.chuangke.common.http.HttpResult;
import com.chuangke.system.entity.SysRelationGraph;
import com.chuangke.system.service.SysRelationGraphService;

@RestController
@RequestMapping("relationgraph")
public class SysRelationGraphController {

	@Autowired
	private SysRelationGraphService sysRelationGraphService;
	
	@PreAuthorize("hasAuthority('login:action')")
	@PostMapping(value = "/save")
	public HttpResult save(@RequestBody List<SysRelationGraph> records) {
		sysRelationGraphService.save(records);
		return HttpResult.ok();
	}

	@PreAuthorize("hasAuthority('login:action')")
	@PostMapping(value = "/delete")
	public HttpResult deleteByIds(@RequestBody List<String> ids) {
		sysRelationGraphService.deleteByIds(ids) ;
		return HttpResult.ok();
	}
	
	@PreAuthorize("hasAuthority('login:action')")
	@PostMapping(value = "/deletebyobject")
	public HttpResult deleteByObjectId(@RequestBody List<String> ids) {
		sysRelationGraphService.deleteByObjectId(ids) ;
		return HttpResult.ok();
	}
	
	@PreAuthorize("hasAuthority('login:action')")
	@GetMapping(value = "/deeplist")
	public HttpResult findDeepRelationByObjectId(@RequestParam String objectId) {
		return HttpResult.ok(sysRelationGraphService.findDeepRelationByObjectId(objectId,null));
	}
	
	@PreAuthorize("hasAuthority('login:action')")
	@GetMapping(value = "/directlist")
	public HttpResult findDirectRelationByObjectId(@RequestParam String objectId) {
		return HttpResult.ok(sysRelationGraphService.findDirectRelationByObjectId(objectId,null));
	}

	@PreAuthorize("hasAuthority('login:action')")
	@GetMapping(value = "/list")
	public HttpResult findList() {
		return HttpResult.ok(sysRelationGraphService.findList());
	}

}
